import {
  REDIS_SKYNET_LOGIN,
  REDIS_SKYNET_LOGOUT,
  REDIS_JANUS_LOGIN,
  REDIS_JANUS_LOGOUT,
} from '../../common/redisChannels';
import outgoingEvents from './eventTypes';

const eventMappings = {
  [REDIS_JANUS_LOGIN]: outgoingEvents.JANUS_LOGIN,
  [REDIS_JANUS_LOGOUT]: outgoingEvents.JANUS_LOGOUT,
  [REDIS_SKYNET_LOGIN]: outgoingEvents.SKYNET_LOGIN,
  [REDIS_SKYNET_LOGOUT]: outgoingEvents.SKYNET_LOGOUT,
};

class ClientStatusHandler {
  static handle(context, payload, { topic }) {
    const outgoingEvent = eventMappings[topic];

    if (!outgoingEvent) return;
    context.socket.emit(outgoingEvent, payload);
  }
}

export default ClientStatusHandler;
